'''
分组执行用例@pytest.mark.smoking
'-m','smoking'  或者  '-m','smoking or smoking2'

无条件跳过
@pytest.mark.skip(reason="XXX")
有条件跳过
@pytest.mark.skipif(age>=18,reason='已成年')
用例的执行顺序 -装饰器
@pytest.mark.run(order=x)
'''

import pytest
import os
import importlib
import allure
from Config.config import *
from Config.URL import *


#pytest.main(["-v", "-s", '--reruns=3', f'--alluredir={AllureResult}', "--clean-alluredir"])
#pytest.main(['TestCases/登录/login.py', 'TestCases/组织管理/usermanager_test.py',"-v", "-s", '--reruns=3', "--clean-alluredir"])


AllureReport = test_report_dir
AllureResult = test_result_dir
Screenshot = test_screenshot_dir
os.system(f"del {os.path.join(Screenshot, '*.png')}")
pytest.main(["-v", "-s", f'--alluredir={AllureResult}', "--clean-alluredir",'-m 施工通用'])  # '-m testing'  or 质量管理 or 法人管理 or 登录 or 组织管理 or 监理管理

#调用生成报告
os.system(f'allure generate {AllureResult} -o {AllureReport} --clean')

#打开报告
os.system(f'allure open {AllureReport}')


# def execute_pytest(file_path):
#
#
#
#     # 加载测试用例
#     module_path = os.path.abspath(file_path)
#     module_name = os.path.splitext(os.path.basename(module_path))[0]
#     spec = importlib.util.spec_from_file_location(module_name, module_path)
#     module = importlib.util.module_from_spec(spec)
#     spec.loader.exec_module(module)
#
#     # 运行 pytest 测试用例
#     result = pytest.main(["-q", module_path])
#
#     return result
#
#
# # Press the green button in the gutter to run the script.
# if __name__ == '__main__':
#
#     # 动态加载 pytest 测试用例并执行
#     execute_pytest(["TestCases/登录/login.py","TestCases/登录/usermanager_test.py"])
#
#     # 加载非测试用例并执行
#     #module = importlib.import_module("my_module")
#     #module.my_function()
#
# # See PyCharm help at https://www.jetbrains.com/help/pycharm/
